package com.zhuotong.myapplicationts;

import android.app.ActivityManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import java.lang.reflect.Method;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView tv = (TextView) findViewById(R.id.tv);
        PackageManager pm = getPackageManager();
        List<ApplicationInfo> infos = pm.getInstalledApplications(0);
        for (ApplicationInfo info : infos) {
            if (info.packageName.equals("com.txy.anywhere")) {
                tv.setText("find txy ApplicationInfo");
            }
        }

        List<PackageInfo> list = pm.getInstalledPackages(0);
        for (PackageInfo info : list) {
            if (info.packageName.equals("com.txy.anywhere")) {
                tv.append("\nfind txy PackageInfo");
            }
        }

        ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> services = am.getRunningServices(100);
        for (ActivityManager.RunningServiceInfo service : services) {
            if (service.process.contains("com.txy.anywhere")) {
                tv.append("\nfind txy RunningServiceInfo");
            }
        }

        List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = am.getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo info : runningAppProcesses) {
            if (info.processName.contains("com.txy.anywhere")) {
                tv.append("\nfind txy RunningAppProcessInfo");
            }
        }

        List<ActivityManager.RunningTaskInfo> runningTasks = am.getRunningTasks(100);
        for (ActivityManager.RunningTaskInfo info : runningTasks) {
            if (info.baseActivity.toString().contains("com.txy.anywhere")) {
                tv.append("\nfind txy RunningAppProcessInfo");
            }
        }

        try {
            Class<?> aClass = Class.forName("com.zhuotong.mylibrary.JustTest");
            Method log = aClass.getDeclaredMethod("log", String.class);
            log.setAccessible(true);
            log.invoke(null,"JENKINS test");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
